<template>
  <div class="header">
    <van-icon name="arrow-left" class="icon" @click="$router.back()"/>
    <span>{{title}}</span>
    <div class="edit" v-if="edit" v-show="store.state.isDelete" @click="handleDelete">
      编辑
    </div>
    <div class="edit" v-if="edit" v-show="!store.state.isDelete" @click="handleDelete">
      完成
    </div>
  </div>
</template>

<script>
import { showToast } from 'vant';
import 'vant/es/toast/style';
import {useStore} from 'vuex'
export default {
    props:['title','edit'],
    setup() {
      const store = useStore()
      const handleDelete = ()=>{
        if(store.state.cartSum.length){
          store.commit('changeDelete')
        }else{
          showToast('请添加商品到购物车')
        }
        
        
      }
      return {
        handleDelete,
        store
      }
    }
}
</script>

<style lang="less" scoped>
.header {
    background-color: #fff;
    height: 40px;
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid #d7d7d7;
    .edit {
      font-size: 16px;
      position: absolute;
      right: 15px;
      font-weight: normal;
    }
    .icon {
      position: absolute;
      left: 10px;
    }
  }
</style>



